package com.yangye.otherdemo.blockingqueue;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author yangye
 * @date 2020/08/17
 */
public class ConditionTest {

	private static ReentrantLock lock = new ReentrantLock();

	public static void main(String[] args) {
		Condition condition = lock.newCondition();

		new Thread(() -> {
			try {
				lock.lock();
				System.out.println("条件等待");
				condition.await();
				System.out.println("被唤醒");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}).start();
		new Thread(() -> {
			try {
				lock.lock();
				System.out.println("唤醒条件");
				condition.signal();
			} finally {
				System.out.println("线程2释放锁");
				lock.unlock();
			}
		}).start();
	}
}
